﻿#region  文件信息
// ---------------------------------------------------------------------------------------
// <copyright file="SubJsonBase.cs" company="">
// 作者：李帅伦
// </copyright>
// <summary>
// 类型简介：
// 类型详细：SubJsonBase.cs
// 创建时间：2015-03-06 19:18
// 修改时间：2015-03-06 18:31
// </summary>
// ---------------------------------------------------------------------------------------
#endregion
 
using System.ComponentModel;
using Newtonsoft.Json;
using WebCommon.Com;

namespace WebCommon.Api
{

    #region

    #endregion

    /// <summary>
    ///     提交json
    /// </summary>
    //[JsonObject(MemberSerialization.OptIn)]
    public class SubPost<T>:SubBase
    { 
        /// <summary>
        ///     数据集
        /// </summary>
        [JsonProperty( NullValueHandling = NullValueHandling.Ignore)]
        [DisplayName("数据集对象")] 
        public virtual T Data { get; set; } 
        #region Public Methods and Operators



        /// <summary>
        /// 查看密钥是否正确
        /// </summary>
        /// <param name="key">
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected override bool IsSuids(string key)
        {
            if (this.IsValidate)
            {
                var m = this.Check;
                var keyValuePairs = Static.GetObjNameValue(Data);
                var datastr = Static.GetOrderBy(keyValuePairs);
                var datakeyStr = $"{datastr}&Key={key}";
                var md5 = Encryption.Md532(datakeyStr);

                var b= m == md5;
                if (b)
                {
                    return true;
                }
                else
                {
                    this.Msg =$"加密错误,Md5={md5},加密数据={datakeyStr}";
                    return false;
                } 
            }
            
            return false;
        }

        #endregion
 


    }
}